					Tutorial Number: 01

TITLE: Study Of Unix Commands

NAME: Bhushan Agrawal			ROLLNO: 01

CLASS: C                     BRANCH: Computer                         BATCH: C1

DATE OF PERFORMANCE: 06/01/2015



1. Change your password to a password you would like to use for the remainder of 
the semester. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ passwd 
	Changing password for bhushan. 
	(current) UNIX password: 
	Enter new UNIX password: 
	Retype new UNIX password: 
	passwd: password updated successfully 
	(changing password from 0811 to bhushan8)

2. Display the system’s date. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ date +%D 
	01/10/15 
	{bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ date +%F 
	  2015-01-10 }

3. Count the number of lines in the /etc/passwd file. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:/etc$ wc passwd 
	  37   61 1829 passwd 

4. Find out who else is on the system. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ who 
	bhushan  tty7         2015-01-10 19:42 (:0) 
	bhushan  pts/0        2015-01-10 20:00 (:0.0) 
	bhushan  pts/1        2015-01-10 20:01 (:0.0) 	

5. Direct the output of the man pages for the date command to a file named mydate. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ man date >mydate .

6. Create a subdirectory called mydir. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ mkdir mydir 

7. Move the file mydate into the new subdirectory. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ mv mydate mydir/ 
	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~/mydir$ ls 
	mydate 

8. Go to the subdirectory mydir and copy the file mydate to a new file called 
ourdate 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~/mydir$ cp mydate ourdate 
9. List the contents of mydir. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~/mydir$ ls 
	mydate  ourdate 

10. Do a long listing on the file ourdate and note the permissions. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~/mydir$ ls -l 
	total 16 
	-rw-rw-r-- 1 bhushan bhushan 6473 Jan 10 20:04 mydate 
	-rw-rw-r-- 1 bhushan bhushan 6473 Jan 10 20:17 ourdate 	

11. Display the name of the current directory starting from the root. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~/mydir$ pwd 
	/home/bhushan/mydir 

12. Move the files in the directory mydir back to the HOME directory. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~/mydir$ mv mydate ourdate .. 	

13. List all the files in your HOME directory. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ ls -a 
.                                     resume.dat.old 
..                                    rss.dat 
02_intro_to_emacs                     rss.dat.old 
127.0.0.1:8000                           settings.dat 
.adobe                                         settings.dat.old 
.android                                      share 
.appletviewer                             .smex-items 
.armagetronad                            .speech-dispatcher 
a.sh                                             .sqlite_history 
a.sh~                                 	    .ssh 
.aspell.en.prepl                           .swp 
.aspell.en.pws                            Templates 
backup.emacs.d                        .thunderbird 
.bash_history                             .tor 
.bash_logout                              Ubuntu One 
.bashrc                                       .vidalia 
.BillardGL.conf.v7                    Videos 
.blobby                                      wallpapers 
.bluefish                                    workspace 
.cache                                       .Xauthority 
Calibre Library                        .Xauthority.0I541W 
.cellwriter                                .Xauthority.1Q1K4W 
.codeblocks                             .Xauthority.2GUX2W 
.compiz                                   .Xauthority.2OPF3W 
.config                                     .Xauthority.2UYM4W 
cookies.txt                              .Xauthority.35CN3W 
.dbus                                       .Xauthority.3B492W 
Desktop                                  .Xauthority.3RF21W 
dht.dat                                    .Xauthority.50L01W 
dht.dat.old                              .Xauthority.5JRG3W 
dht_feed.dat                           .Xauthority.6CJI4W 
dht_feed.dat.old                     .Xauthority.7ELB3W 
.dmrc                                      .Xauthority.7LJ43W 
Documents                             .Xauthority.86661W 
Downloads                             .Xauthority.8V6L2W 
.dreamchess                            .Xauthority.97B21W 
.easystroke                             .Xauthority.983J2W 
.emacs.d                                .Xauthority.9Y0C3W 
examples.desktop                  .Xauthority.ATWL4W 
.gconf                                    .Xauthority.BGTY3W 
gedit-3.9.9                             .Xauthority.BXBY4W 
.git                                         .Xauthority.CTTG2W 
.gitconfig                              .Xauthority.D4C41W 
.gksu.lock                             .Xauthority.D55C2W 
.gnome2                                .Xauthority.EK5Y4W 
.gnome2_private                   .Xauthority.EW1H4W 
.gnupg                                   .Xauthority.F39A2W 
.gphoto                                  .Xauthority.FER52W 
.gstreamer-0.10                     .Xauthority.FJPD3W 
.gvfs                                     .Xauthority.H91B2W 
hts-cache                              .Xauthority.HIUG2W 
hts-in_progress.lock             .Xauthority.HMNT4W 
hts-log.txt                             .Xauthority.KVIR2W 
.ICEauthority                       .Xauthority.L0EF4W 
.icedtea                                 .Xauthority.LJYL2W 
.icons                                   .Xauthority.NFOP3W 
.ido.last                                .Xauthority.NN5X2W 
install_flash_player_11_linux.x86_64  .Xauthority.O55C2W 
.IntelliJIdea13                      .Xauthority.OUYK2W 
.java                                     .Xauthority.POKU2W 
.lesshst                                 .Xauthority.QGH23W 
libgraph-1.0.2                      .Xauthority.RJOW3W 
.local                                    .Xauthority.T0FQ3W 
.macromedia                        .Xauthority.TICO3W 
.mozilla                               .Xauthority.TOTZ1W 
Music                                  .Xauthority.TQR02W 
mydate                                .Xauthority.TXTB3W 
mydir                                  .Xauthority.V67I4W 
.nemiver                              .Xauthority.VQF73W 
NEW                                   .Xauthority.W7TF4W 
.onboard                              .Xauthority.WPEJ1W 
ourdate                                .Xauthority.WTZX3W 
Pictures                               .Xauthority.XRD51W 
.pki                                      .Xauthority.XW051W 
.profile                                 .Xauthority.Y8JW3W 
Public                                  .xsession-errors 
resume.dat                           .xsession-errors.old 	

14. Display the first 5 lines of mydate. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ head mydate -n 5 
DATE(1)                          User Commands                         DATE(1) 



NAME 
15. Display the last 8 lines of mydate. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ tail mydate -n 8 

              info coreutils 'date invocation' 

       should give you access to the complete manual. 



GNU coreutils 8.20               October 2012                          DATE(1) 

16. Remove the directory mydir. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ rmdir mydir/ 

17. Redirect the output of the long listing of files to a file named list. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ ls -l >list 

18. Select any 5 capitals of states in India and enter them in a file named capitals1. 
Choose 5 more capitals and enter them in a file named capitals2. Choose 5 more 
capitals and enter them in a file named capitals3. Concatenate all 3 files and 
redirect the output to a file named capitals. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ cat > capitals1
Mumbai
Delhi
Hyderabad
Jaipur
Chennai

bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ cat > capitals2
Srinagar
Guwahati
Kolkata
Patna
Chandigarh

bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ cat > capitals3
Panaji
Gandhinagar
Shimla
Ranchi
Bengaluru

bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ cat capitals1 capitals2 capitals3 >> capitals

19. Concatenate the file capitals2 at the end of file capitals. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ cat capitals2 >> capitals
bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ cat capitals
Mumbai
Delhi
Hyderabad
Jaipur
Chennai
Srinagar
Guwahati
Kolkata
Patna
Chandigarh
Panaji
Gandhinagar
Shimla
Ranchi
Bengaluru
Srinagar
Guwahati
Kolkata
Patna
Chandigarh
 
20. Redirect the file capitals as an input to the command “wc –l”. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ wc -l < capitals
	20

21. Give read and write permissions to all users for the file capitals. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ ls -l capitals
-rw-rw-r-- 1 bhushan bhushan 167 Jan 10 23:51 capitals
bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ chmod 666 capitals
bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ ls -l capitals
-rw-rw-rw- 1 bhushan bhushan 167 Jan 10 23:51 capitals

22. Give read permissions only to the owner of the file capitals. Open the file, make 
some changes and try to save it. What happens ? 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ chmod 400 capitals
bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ ls -l capitals
-r-------- 1 bhushan bhushan 167 Jan 10 23:51 capitals
bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ cat > capitals
bash: capitals: Permission denied

23. Create an alias to concatenate the 3 files capitals1, capitals2, capitals3 and 
redirect the output to a file named capitals. Activate the alias and make it run. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ alias "bka=cat capitals1 capitals2 capitals3 > capitals"
bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ bka
bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ cat capitalsMumbai
Delhi
Hyderabad
Jaipur
Chennai
Srinagar
Guwahati
Kolkata
Patna
Chandigarh
Panaji
Gandhinagar
Shimla
Ranchi
Bengaluru

24. What are the environment variables PATH, HOME and TERM set to on your 
terminal ? 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ echo $HOME
/home/bhushan
bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ echo $TERM
xterm

25. Find out the number of times the string “the” appears in the file mydate. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ grep -c "the" mydate
	20

26. Find out the line numbers on which the string “date” exists in mydate. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ grep -n "date" mydate 
6:       date - print or set the system date and time
9:       date [OPTION]... [+FORMAT]
10:       date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
13:       Display the current time in the given FORMAT, or set the system date.
15:       -d, --date=STRING
19:              like --date once for each line of DATEFILE
22:              output  date/time  in ISO 8601 format.  TIMESPEC='date' for date
24:              date and time to the indicated precision.
30:              output  date  and time in RFC 2822 format.  Example: Mon, 07 Aug
34:              output date and time in RFC 3339 format.  TIMESPEC='date', 'sec‐
35:              onds',  or  'ns'  for  date and time to the indicated precision.
62:       %c     locale's date and time (e.g., Thu Mar  3 23:05:25 2005)
68:       %D     date; same as %m/%d/%y
72:       %F     full date; same as %Y-%m-%d
124:       %x     locale's date representation (e.g., 12/31/99)
143:       By default, date  pads  numeric  fields  with  zeroes.   The  following
162:       Convert seconds since the epoch (1970-01-01 UTC) to a date
164:              $ date --date='@2147483647'
168:              $ TZ='America/Los_Angeles' date
172:              $ date --date='TZ="America/Los_Angeles" 09:00 next Fri'
175:       The --date=STRING is a mostly free format human  readable  date  string
177:       even "next Thursday".  A date string may contain items indicating  cal‐
178:       endar  date,  time of day, time zone, day of week, relative time, rela‐
179:       tive date, and numbers.  An empty string indicates the beginning of the
180:       day.   The date string format is more complex than is easily documented
187:       Report date bugs to bug-coreutils@gnu.org
190:       Report date translation bugs to <http://translationproject.org/team/>
199:       The full documentation for date is maintained as a Texinfo manual.   If
200:       the  info  and  date  programs are properly installed at your site, the
203:              info coreutils 'date invocation'

27. Print all lines of mydate except those that have the letter “i” in them. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ grep -v "i" mydate 
DATE(1)                          User Commands                         DATE(1)



NAME

SYNOPSIS
       date [OPTION]... [+FORMAT]

DESCRIPTION

       -d, --date=STRING



       -r, --reference=FILE

       -R, --rfc-2822
              2006 12:34:56 -0600

       --rfc-3339=TIMESPEC
              2006-08-07 12:34:56-06:00

       -s, --set=STRING




       FORMAT controls the output.  Interpreted sequences are:



       %A     locale's full weekday name (e.g., Sunday)


       %B     locale's full month name (e.g., January)



       %d     day of month (e.g., 01)

       %D     date; same as %m/%d/%y

       %e     day of month, space padded; same as %_d

       %F     full date; same as %Y-%m-%d



       %h     same as %b

       %H     hour (00..23)

       %I     hour (01..12)

       %j     day of year (001..366)

       %k     hour, space padded ( 0..23); same as %_H

       %l     hour, space padded ( 1..12); same as %_I

       %m     month (01..12)



       %N     nanoseconds (000000000..999999999)






       %S     second (00..60)

       %t     a tab










       %Y     year




              +05:30)









EXAMPLES

              $ date --date='@2147483647'





DATE STRING
       such  as  "Sun, 29 Feb 2004 16:21:42 -0800" or "2004-02-29 16:21:42" or

AUTHOR

REPORTING BUGS

COPYRIGHT

SEE ALSO
       command






28. List 5 states in north east India in a file mystates. List their corresponding 
capitals in a file mycapitals. Use the paste command to join the 2 files. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ cat > mystates 
Assam
Tripura
Mizoram
Sikkim
Nagaland
bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ cat > mycapitals 
Guwahati
Agartala
Aizawl
Gangtok
Kohima
bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ paste mystates mycapitals 
Assam	Guwahati
Tripura	Agartala
Mizoram	Aizawl
Sikkim	Gangtok
Nagaland	Kohima

29. Use the cut command to print the 1st and 3rd columns of the /etc/passwd file for 
all students in this class. 
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ cut -c 1,3 /etc/passwd
ro
de
bn
ss
sn
gm
mn
l:
mi
nw
uc
po
ww
bc
ls
ic
ga
nb
lb
ss
ms
aa
ub
ds
wo
kr
rk
se
lg
aa
cl
pl
hl
sn
bu
tj
db

30. Count the number of people logged in and also trap the users in a file using the 
tee command.
=>	bhushan@bhushan-HP-Pavilion-g6-Notebook-PC:~$ who | wc -l | tee count
	3

